
#include "roomchat.h"
#include "chatbase.h"
#include "RtInetAddr.h"

extern CRtConfigInitFile IniFile;
void chatConfig::Initialize()
{
	m_LocalIp.strIP = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_CHAT_IP);
	m_LocalIp.nPort = IniFile.GetDwordParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_BIND_PORT);
	m_LocalIp.nType = NET_PROTOCOL_TCP;
	
	m_BindPort = IniFile.GetDwordParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_BIND_PORT);
	
	strMMHost = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_MEMCACHE_HOST);
	dwMMPort = IniFile.GetDwordParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_MEMCACHE_PORT, 11211);
	strMMName = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_MEMCACHE_NAME);
	strMMUserName = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_MEMCACHE_USER);
	strMMPassword = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_MEMCACHE_PWD);

	strPGHost = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_PG_HOST);
	dwPGPort = IniFile.GetDwordParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_PG_PORT, 5432);
	strPGName = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_PG_NAME);
	strPGUserName = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_PG_USER);
	strPGPassword = IniFile.GetStringParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_PG_PWD);

	m_dwDbThreadNum = IniFile.GetDwordParam(SKY_CFG_GROUP_CHAT, SKY_CFG_ITEM_DB_THREAD_NUM);
}

CRoomChat* CRoomChat::Instance()
{
	return CRoomChatSingleton::Instance();
}

CRoomChat::CRoomChat()
: m_pRoomModule(NULL)
{

}

CRoomChat::~CRoomChat()
{
	RT_INFO_TRACE("CRoomChat::~CRoomChat");
	Release();
}

RtResult CRoomChat::Initialize()
{
	RT_INFO_TRACE_THIS("vcs_chat starting, version: "<<SKY_VCS_ME_VERSION);
	RtResult rv = RT_OK;
	m_config.Initialize();

	/* Initialize CDataSource */
	m_pRoomModule = IRoomModule::Instance();
	if (NULL == m_pRoomModule){
		return RT_ERROR_NULL_POINTER;
	}

	rv = m_pRoomModule->Initialize(m_config);
	if (RT_FAILED(rv))
	{
		RT_ERROR_TRACE("CRoomChat::Initialize, IRoomModule Initialize failed! rv: "<<rv);
		return rv;
	}
	return rv;
}

void CRoomChat::Release()
{
	RT_INFO_TRACE("CRoomChat::Release");
}
